import * as echarts from 'echarts'
// ! 事件统计
export const eventCountListData = (data) => {
  let xdata = [],
    ydata = []
  let cusEnum = {
    checkOverdueCount: '检查逾期',
    overdueReceiptCount: '回执逾期',
    reviewOverdueCount: '复查逾期',
    failedToReviewCount: '复查不合格',
  }
  data.forEach((item) => {
    ydata.push(item.values)
    xdata.push(cusEnum[item.key])
  })
  let options = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow',
      },
    },
    grid: {
      top: '15%',
      left: '3%',
      right: '3%',
      bottom: '5%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        data: xdata,
        axisLine: {
          lineStyle: {
            color: '#509EEE',
          },
        },
        axisLabel: {
          margin: 10,
          color: '#ffffff',
          // color: '#509EEE',
          textStyle: {
            fontSize: '.12rem',
            fontFamily: 'PingFang SC',
            fontWeight: 500,
          },
        },
      },
    ],
    yAxis: [
      {
        nameTextStyle: {
          padding: [0, 40, 0, 0], // 四个数字分别为上右下左与原位置距离
        },
        minInterval: 1,
        axisLabel: {
          padding: 0,
          color: '#ffffff',
          textStyle: {
            fontSize: '.12rem',
            fontFamily: 'PingFang SC',
            fontWeight: 900,
          },
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: '#509EEE',
          },
        },
        splitLine: {
          show: false,
        },
      },
    ],
    series: [
      {
        type: 'bar',
        data: ydata,
        barWidth: '24px',
        itemStyle: {
          normal: {
            show: true,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#02d1dc' },
              { offset: 1, color: '#0c4075' },
            ]),
          },
        },
      },
    ],
  }
  return options
}

// ! 检查次数统计
export const checkCountData = (data) => {
  let xdata = [],
    ydata = []
  data.forEach((item) => {
    if (item.inTime.length > 6) {
      xdata.push(item.inTime.substring(item.inTime.length - 5))
    } else {
      xdata.push(item.inTime)
    }
    ydata.push(item.count)
  })
  let options = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow',
      },
    },
    grid: {
      top: '12%',
      left: '2%',
      right: '5%',
      bottom: '3%',
      containLabel: true,
    },
    legend: {
      top: '1%',
      right: '10%',
      itemStyle: {
        color: '#509EEE',
      },
      textStyle: {
        fontSize: 14, //字体大小
        color: '#509EEE',
      },
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        data: xdata,
        axisLine: {
          lineStyle: {
            color: '#1171d4',
          },
        },
        axisLabel: {
          margin: 10,
          rotate: 0,
          color: '#ffffff',
          textStyle: {
            fontSize: '.12rem',
            fontFamily: 'PingFang SC',
            fontWeight: 500,
          },
        },
      },
    ],
    yAxis: [
      {
        // name: '(次)',
        nameTextStyle: {
          padding: [0, 30, 0, 0], // 四个数字分别为上右下左与原位置距离
        },
        minInterval: 1,
        axisLabel: {
          color: '#ffffff',
          padding: [0, 20, 0, 0],
          textStyle: {
            fontSize: '.12rem',
            fontFamily: 'PingFang SC',
            fontWeight: 900,
          },
          textStyle: {
            align: 'center',
          },
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: '#509EEE',
          },
        },
        splitLine: {
          show: false,
        },
      },
    ],

    series: [
      {
        // name: "次数",
        type: 'line',
        smooth: true, //是否平滑曲线显示
        // 			symbol:'circle',  // 默认是空心圆（中间是白色的），改成实心圆
        symbolSize: 0,

        lineStyle: {
          borderWidth: 4,
          normal: {
            color: '#06bbf5', // 线条颜色
          },
        },
        itemStyle: {
          normal: {
            color: '#06bbf5',
          },
        },
        areaStyle: {
          //区域填充样式
          normal: {
            //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
            color: new echarts.graphic.LinearGradient(
              0,
              0,
              0,
              1,
              [
                { offset: 0, color: 'rgba(6, 41, 76, 0.2) ' },
                { offset: 1, color: 'rgba(3, 151, 255, 0.6)' },
              ],
              false
            ),

            shadowColor: 'rgba(53,142,215, 0.9)', //阴影颜色
            shadowBlur: 0, //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
          },
        },
        data: ydata,
      },
    ],
  }

  return options
}
